<?php namespace Admin\Controller; 

//后台默认控制器
class IndexController extends CommonController{
    //首页
    public function index(){
    		View::make();
    }
	
	//欢迎界面
	public function welcome(){
	    View::make();
	}
	
	//修改密码
	public function changePassword(){
		if(IS_POST){
		 $newPassword = Q('post.newPassword');
		 if(strlen($newPassword)<6) View::error('新密码不得少于6位');
		 
		  $confirmPassword = Q('post.confirmPassword');
		  if($newPassword != $confirmPassword) View::error('两次密码不一致');
		  
		  $uid = $_SESSION['info']['uid'];
		  $data = Db::table('doov_user')->where("uid={$uid}")->get();
		  $oldPassword = Q('post.oldPassword','','md5');
		  if($oldPassword != $data[0]['password']) View::error('原密码错误');

		  Db::table('doov_user')->where("uid={$uid}")->update(['password'=>md5($newPassword)]);
		  
		  session_unset();
		  session_destroy();
		  echo '<script>parent.location.href="'.U('Login/index').'"</script>';
		  exit;
		  
		}
		View::make();
	}
}
